import Swal, {SweetAlertIcon} from 'sweetalert2';
import {handleFetch} from "next/dist/experimental/testmode/proxy/fetch-api";


const showCustomAlertError = (title: any, text: any) => {
    Swal.fire({
        title: title,
        text: text,
        icon:  "error" ,
        confirmButtonText: '确定',
        didOpen: () => {
            // 获取提示框元素
            const swalPopup = document.querySelector('.swal2-popup');
            const swalTitle = document.querySelector('.swal2-title'); // 获取标题元素
            const swalIcon = document.querySelector('.swal2-icon'); // 获取图标元素

            if (swalPopup) {
                (swalPopup as HTMLElement).style.width = '300px'; // 设置宽度
                (swalPopup as HTMLElement).style.maxWidth = '90%'; // 设置最大宽度
                (swalPopup as HTMLElement).style.height = '340px'; // 设置高度
            }

            if (swalTitle) {
                (swalTitle as HTMLElement).style.fontSize = '18px'; // 设置标题字体大小
            }

            if (swalIcon) {
                (swalIcon as HTMLElement).style.width = '78px'; // 设置图标宽度
                (swalIcon as HTMLElement).style.height = '76px'; // 设置图标高度
            }
        }
    });
};

const showCustomAlertSuccess = (title: any, text: any) => {
    Swal.fire({
        title: title,
        text: text,
        icon:  "success" ,
        confirmButtonText: '确定',
        didOpen: () => {
            // 获取提示框元素
            const swalPopup = document.querySelector('.swal2-popup');
            const swalTitle = document.querySelector('.swal2-title'); // 获取标题元素
            const swalIcon = document.querySelector('.swal2-icon'); // 获取图标元素

            if (swalPopup) {
                (swalPopup as HTMLElement).style.width = '300px'; // 设置宽度
                (swalPopup as HTMLElement).style.maxWidth = '90%'; // 设置最大宽度
                (swalPopup as HTMLElement).style.height = '340px'; // 设置高度
            }

            if (swalTitle) {
                (swalTitle as HTMLElement).style.fontSize = '18px'; // 设置标题字体大小
            }

            if (swalIcon) {
                (swalIcon as HTMLElement).style.width = '78px'; // 设置图标宽度
                (swalIcon as HTMLElement).style.height = '76px'; // 设置图标高度
            }
        }
    });
};

const getAward = (prizeName: string) => {
    Swal.fire({
        title: '恭喜中奖！',  // 设置标题
        html: `
            恭喜你抽中奖品💐<br>
            【<strong>${prizeName}</strong>】`,  // 设置内容，包含奖品名称
        icon: 'success',
        confirmButtonText: '确定',
        didOpen: () => {
            // 获取提示框元素
            const swalPopup = document.querySelector('.swal2-popup');
            const swalTitle = document.querySelector('.swal2-title'); // 获取标题元素
            const swalIcon = document.querySelector('.swal2-icon'); // 获取图标元素

            if (swalPopup) {
                (swalPopup as HTMLElement).style.width = '300px'; // 设置宽度
                (swalPopup as HTMLElement).style.maxWidth = '90%'; // 设置最大宽度
                (swalPopup as HTMLElement).style.height = '340px'; // 设置高度
            }

            if (swalTitle) {
                (swalTitle as HTMLElement).style.fontSize = '18px'; // 设置标题字体大小
            }

            if (swalIcon) {
                (swalIcon as HTMLElement).style.width = '78px'; // 设置图标宽度
                (swalIcon as HTMLElement).style.height = '76px'; // 设置图标高度
            }
        }
    });
};
export  {showCustomAlertSuccess, showCustomAlertError, getAward};
